//
//  SettingCell.m
//  SinaWeibo
//
//  Created by Apple on 16/8/22.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "SettingCell.h"
#import "ItemModel.h"
#import "GroupModel.h"
#import "ItemSwitchModel.h"
#import "ItemArrowModel.h"
#import "ItemLogoutModel.h"
#import "ItemPictureQualityModel.h"


@implementation SettingCell

-(void)setItem:(ItemModel *)item{
    
    _item = item;
    
    //设置背景图片
    
    
    //如果icon是空就会报下面的警告
    //CUICatalog: Invalid asset name supplied: (null)
    if (item.icon) {
        self.imageView.image = [UIImage imageNamed:item.icon];
    }
    //设置标题
    self.textLabel.text = item.title;
    self.textLabel.font = [UIFont systemFontOfSize:16];
    
    //设置detialLabel字体和颜色
    self.detailTextLabel.text = item.subTitle;
    
    self.detailTextLabel.textColor = [UIColor grayColor];
    
    self.detailTextLabel.font = [UIFont systemFontOfSize:12];
    
    //判断模型的类型
    if ([item isKindOfClass:[ItemArrowModel class]]) {
        
        self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_icon_arrow"]];
        
    }else if([item isKindOfClass:[ItemSwitchModel class]]){
        
        self.accessoryView = [[UISwitch alloc]init];
        
    }else if ([item isKindOfClass:[ItemPictureQualityModel class]]){
        
        ItemPictureQualityModel *picQuality = (ItemPictureQualityModel *)item;
        if (picQuality.isCheck) {
            self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_icon_checkmark"]];
        }else{
            self.accessoryView = nil;
        }
    }
    
}


//重写init方法设置为分组

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    if([self.item isKindOfClass:[ItemLogoutModel class]]){
        
        self.textLabel.center = CGPointMake(self.frame.size.width *0.5, self.frame.size.height*0.5);
        
        self.textLabel.textColor = [UIColor redColor];
    }
}



@end
